<template>
	<view >
		<tui-tips ref="toast"
		 backgroundColor="#00CD66"></tui-tips>
		<view class="card-info">
			<view class="vip-info">
				<uni-row >
				    <uni-col :span="6">
						姓名
					</uni-col>
					<uni-col :span="16">
						{{vipCard.realName}}
					</uni-col>
				</uni-row>
				<uni-row>
				    <uni-col :span="6">
						卡号
					</uni-col>
					<uni-col :span="16">
						{{vipCard.cardId}}
					</uni-col>
				</uni-row>
			</view>
			<view class="icon-info">
				<tui-icon name="bankcard"
				 :size="48"
				 color="#ffffff"></tui-icon>
			</view>
		</view>
		<view class="deposit-info">
			<view class="deposit-card">
				<view class="cash-info" v-for="(item, index) in cashList"
				        :key="index"
						@click="chooseMoney(item.sm)">
					<text class="cash-bg">{{item.bg}}元</text>
					<text class="cash-sm">售价:{{item.sm}}元</text>
				</view>
			</view>
		</view>
		<!-- 确认支付框 -->
		<tui-modal :show="depVisible" 
				custom>
			<view class="tui-modal-title">充值</view>
			<view class="tui-modal-content">
				<view class="tui-modal-custom-text">确定充值{{money}}元？</view>
			</view>
			<view class="tui-modalBtn-box">
				<tui-button  class="tui-modal-btn" type="primary" shape="circle"  @click.native="depositMoney()">确定</tui-button>
				<tui-button class="tui-modal-btn" type="info" shape="circle"  @click.native="closeModal()">取消</tui-button>
			</view>
		</tui-modal>
	</view>
	
</template>

<script>
import {addDeposit} from '@/api/index.js'
export default {
	data(){
		return {
			money: 0,
			vipCard: {},
			cashList: [
				{bg: 100, sm: 100},
				{bg: 200, sm: 200},
				{bg: 300, sm: 300},
				{bg: 500, sm: 500},
				{bg: 1000, sm: 1000},
				{bg: 3000, sm: 3000},
			],
			depVisible: false
		}
	},
	created(){
		this.vipCard = uni.getStorageSync("card_info") || {};
	},
	methods: {
		chooseMoney(money){
			this.money = money;
			this.depVisible = true;
		},
		depositMoney(money){
			let _this = this;
			// uni.requestPayment({
			//     "provider": "wxpay", 
			//     "orderInfo": {
			//         "appid": "wx499********7c70e",  // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
			//         "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串
			//         "package": "Sign=WXPay",        // 固定值
			//         "partnerid": "148*****52",      // 微信支付商户号
			//         "prepayid": "wx202254********************fbe90000", // 统一下单订单号 
			//         "timestamp": 1597935292,        // 时间戳（单位：秒）
			//         "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名，这里用的 MD5/RSA 签名
			//     },
			//     success(res) {
			// 		console.log(res)
			// 	},
			//     fail(e) {
			// 		console.log(e)
			// 	}
			// })
			
			addDeposit({
				cardId: _this.vipCard.cardId,
				money: _this.money,
				type: 0, //充值
				
			}).then(res => {
				if(res.success){
					uni.setStorageSync("card_info", res.result);
					_this.depVisible = false;
					_this.$refs.toast.showTips({
						msg: '充值成功',
						duration: 2000
					});
				}
			})
			
		},
		closeModal(){
			this.depVisible = false;
		}
	}
}
</script>

<style lang="scss">
	@import url("deposit.css");
</style>